<template>
  <div :class="className" :style="{height:height,width:width}" />

</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

export default {
  name: 'LineChart3',
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart1'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    },
    item: {
      type: Object
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      const data = {
        xData: [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70],
        yData1: [10, 20, 50],
        yData2: ['-', '-', 50, 110, 140],
        yData3: ['-', '-', '-', '-', 140, 160, 210, 140],
        yData4: ['-', '-', '-', '-', '-', '-', '-', 140, 210, 160, 140],
        yData5: ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', 140, 110, 50],
        yData6: ['-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', '-', 50, 20, 10]
      }
      this.chart = echarts.init(this.$el, 'macarons')
      this.chart.setOption({
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: [
          {
            top: 50,
            bottom: 101
          },
          {
            height: 60,
            bottom: 40
          }
        ],

        xAxis: [{
          type: 'category',
          data: data.xData,
          gridIndex: 0,
          axisLabel: {
            color: '#333'
          },
          axisLine: {
            lineStyle: {
              color: '#e7e7e7'
            }
          },
          axisTick: {
            lineStyle: {
              color: '#e7e7e7'
            }
          },
          zlevel: 2
        }, {
          type: 'category',
          gridIndex: 1,
          axisLine: {
            show: false
          },
          zlevel: 1
        }],
        yAxis: [{
          type: 'value',
          gridIndex: 0,
          axisLabel: {
            color: 'black'
          },
          splitLine: {
            lineStyle: {
              type: 'dashed'
            }
          },
          axisLine: {
            lineStyle: {
              color: '#ccc'
            }
          },
          axisTick: {
            lineStyle: {
              color: '#ccc'
            }
          }
        }, {
          type: 'value',
          gridIndex: 1,
          axisLabel: {
            show: false
          },
          axisLine: {
            show: false
          },
          splitLine: {
            show: false
          },
          axisTick: {
            show: false
          }
        }],
        series: [{
          data: data.yData1,
          type: 'line',
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#555'
            }
          },
          lineStyle: {
            normal: {
              color: 'rgba(204, 204, 204, 1)'
            }
          },

          // areaStyle: {
          //   color: 'rgba(204, 204, 204, 1)'

          // },
          xAxisIndex: 0,
          yAxisIndex: 0
        },
        {
          data: data.yData2,
          type: 'line',
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#555'
            }
          },
          lineStyle: {
            normal: {
              color: 'rgba(57, 172, 255, 1)'
            }
          },

          // areaStyle: {
          //   color: 'rgba(57, 172, 255, 1)'

          // },
          xAxisIndex: 0,
          yAxisIndex: 0
        },
        {
          data: data.yData3,
          type: 'line',
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#555'
            }
          },
          lineStyle: {
            normal: {
              color: 'rgba(109, 212, 0, 1)'
            }
          },

          // areaStyle: {
          //   color: 'rgba(109, 212, 0, 1)'

          // },
          xAxisIndex: 0,
          yAxisIndex: 0
        },
        {
          data: data.yData4,
          type: 'line',
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#555'
            }
          },
          lineStyle: {
            normal: {
              color: 'rgba(109, 212, 0, 1)'
            }
          },

          xAxisIndex: 0,
          yAxisIndex: 0
        },
        {
          data: data.yData5,
          type: 'line',
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#555'
            }
          },
          lineStyle: {
            normal: {
              color: 'rgba(57, 172, 255, 1)'
            }
          },

          xAxisIndex: 0,
          yAxisIndex: 0
        },
        {
          data: data.yData6,
          type: 'line',
          label: {
            show: true,
            position: 'top',
            textStyle: {
              color: '#555'
            }
          },
          lineStyle: {
            normal: {
              color: 'rgba(204, 204, 204, 1)'
            }
          },

          xAxisIndex: 0,
          yAxisIndex: 0
        },
        {
          data: [{
            name: '',
            value: 1
          }],
          label: {
            show: true,
            position: 'inside',
            formatter: '{b}',
            offset: [0, 10],
            textStyle: {
              color: 'black'
            }
          },
          type: 'bar',
          barGap: 0,
          barWidth: '5%',
          itemStyle: {
            normal: {
              color: 'rgb(217,245,231)'
            }
          },
          xAxisIndex: 1,
          yAxisIndex: 1
        }, {
          data: [{
            name: '',
            value: 1
          }],
          label: {
            show: true,
            position: 'inside',
            formatter: '{b}',
            offset: [0, 10],
            textStyle: {
              color: '#777'
            }
          },
          type: 'bar',
          barGap: 0,
          barWidth: '20%',
          itemStyle: {
            normal: {
              color: 'rgb(228,235,253)'
            }
          },
          xAxisIndex: 1,
          yAxisIndex: 1
        }, {
          data: [{
            name: '',
            value: 1
          }],
          label: {
            show: true,
            position: 'inside',
            formatter: '{b}',
            offset: [0, 10],
            textStyle: {
              color: '#777'
            }
          },
          type: 'bar',
          barGap: 0,
          barWidth: '70%',
          itemStyle: {
            normal: {
              color: 'rgb(255,231,204)'
            }
          },
          xAxisIndex: 1,
          yAxisIndex: 1
        }, {
          data: [{
            name: '',
            value: 1
          }],
          label: {
            show: true,
            position: 'inside',
            formatter: '{b}',
            offset: [0, 10],
            textStyle: {
              color: '#777'
            }
          },
          type: 'bar',
          barGap: 0,
          barWidth: '5%',
          itemStyle: {
            normal: {
              color: 'rgb(229,216,253)'
            }
          },
          xAxisIndex: 1,
          yAxisIndex: 1
        }]
      })
    }
  }
}
</script>
